import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    industry: 1,
    city: 1,
    token: sessionStorage.getItem('token') ? sessionStorage.getItem('token') : '',
    name: sessionStorage.getItem('name') ? sessionStorage.getItem('name') : '',
    id: sessionStorage.getItem('id') ? sessionStorage.getItem('id') : '',
    avatar: sessionStorage.getItem('avatar') ? sessionStorage.getItem('avatar') : '',
    Dcity: sessionStorage.getItem('Dcity') ? sessionStorage.getItem('Dcity') : '',
    phone: sessionStorage.getItem('phone') ? sessionStorage.getItem('phone') : '',
    Cid: sessionStorage.getItem('Cid') ? sessionStorage.getItem('Cid') : ''
  },
  mutations: {
    changeLogin (state, user) {
      state.token = user.token
      sessionStorage.setItem('token', user.token)
    },
    changeUName (state, user) {
      state.name = user.name
      sessionStorage.setItem('name', user.name)
    },
    changeUid (state, user) {
      state.id = user.id
      sessionStorage.setItem('id', user.id)
    },
    changeUavatar (state, user) {
      state.avatar = user.avatar
      sessionStorage.setItem('avatar', user.avatar)
    },
    changeDcity (state, user) {
      state.Dcity = user.Dcity
      sessionStorage.setItem('Dcity', user.Dcity)
    },
    changephone (state, user) {
      state.phone = user.phone
      sessionStorage.setItem('phone', user.phone)
    },
    changeDcityId (state, user) {
      state.Cid = user.Cid
      sessionStorage.setItem('Cid', user.Cid)
    }
  }
})
